package com.dems.admin.controller;

import com.dems.admin.security.SecurityUtils;
import com.dems.domain.JsonResponse;
import com.dems.domain.org.*;
import com.dems.service.org.OrgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 组织架构管理
 */
@Slf4j
@RequestMapping("/org")
@RestController
public class OrgController {

    @Autowired
    private OrgService orgService;

    /**
     * 部门
     * @return
     */
    @PostMapping("/deptList")
    public JsonResponse<List<DeptDto>> deptList(@RequestBody DeptDto deptDto) {
        return JsonResponse.success(orgService.deptList(deptDto, SecurityUtils.getLoanassistUser()));
    }

    /**
     * 保存部门
     * @return
     */
    @PostMapping("/saveDept")
    public JsonResponse<DeptDto> saveDept(@RequestBody DeptDto deptDto) {
        return JsonResponse.success(orgService.saveDept(deptDto, SecurityUtils.getLoanassistUser()));
    }

    /**
     * 删除部门
     * @return
     */
    @PostMapping("/deleteDept")
    public JsonResponse<Integer> deleteDept(@RequestBody DeptDto deptDto) {
        return JsonResponse.success(orgService.deleteDept(deptDto, SecurityUtils.getLoanassistUser()));
    }

    /**
     * 保存部门成员
     * @return
     */
    @PostMapping("/deptStaffList")
    public JsonResponse<List<DeptStaffDto>> deptStaffList(@RequestBody DeptStaffDto deptStaffDto) {
        return JsonResponse.success(orgService.deptStaffList(deptStaffDto, SecurityUtils.getLoanassistUser()));
    }

    /**
     * 保存部门
     * @return
     */
    @PostMapping("/deleteDeptStaff")
    public JsonResponse<Integer> deleteDeptStaff(@RequestBody DeptStaffDto deptStaffDto) {
        return JsonResponse.success(orgService.deleteDeptStaff(deptStaffDto, SecurityUtils.getLoanassistUser()));
    }

    /**
     * 保存部门员工
     * @return
     */
    @PostMapping("/saveDeptStaff")
    public JsonResponse<List<DeptStaffDto>> saveDeptStaff(@RequestBody List<DeptStaffDto> deptStaffDtoList) {
        return JsonResponse.success(orgService.saveDeptStaff(deptStaffDtoList, SecurityUtils.getLoanassistUser()));
    }

    /**
     * 设置部门员工角色
     * @return
     */
    @PostMapping("/saveDeptStaffRole")
    public JsonResponse<Integer> saveDeptStaffRole(@RequestBody DeptStaffDto deptStaffDto) {
        return JsonResponse.success(orgService.saveDeptStaffRole(deptStaffDto, SecurityUtils.getLoanassistUser()));
    }

    /**
     * 角色列表
     * @return
     */
    @PostMapping("/roleList")
    public JsonResponse<List<RoleDto>> roleList(@RequestBody RoleDto roleDto) {
        return JsonResponse.success(orgService.roleList(roleDto, SecurityUtils.getLoanassistUser()));
    }
    /**
     * 角色列表
     * @return
     */
    @PostMapping("/staffRoleList")
    public JsonResponse<List<StaffRoleDto>> staffRoleList(@RequestBody RoleDto roleDto) {
        return JsonResponse.success(orgService.staffRoleList(roleDto, SecurityUtils.getLoanassistUser()));
    }

    /**
     * 保存角色
     * @return
     */
    @PostMapping("/saveRole")
    public JsonResponse<RoleDto> saveRole(@RequestBody RoleDto roleDto) {
        return JsonResponse.success(orgService.saveRole(roleDto, SecurityUtils.getLoanassistUser()));
    }

    /**
     * 保存角色
     * @return
     */
    @PostMapping("/saveStaffRole")
    public JsonResponse<Integer> saveStaffRole(@RequestBody List<StaffRoleDto> staffRoleDtoList) {
        return JsonResponse.success(orgService.saveStaffRole(staffRoleDtoList, SecurityUtils.getLoanassistUser()));
    }

    /**
     * 保存角色
     * @return
     */
    @PostMapping("/deleteStaffRole")
    public JsonResponse<Integer> deleteStaffRole(@RequestBody StaffRoleDto staffRoleDto) {
        return JsonResponse.success(orgService.deleteStaffRole(staffRoleDto, SecurityUtils.getLoanassistUser()));
    }

    /**
     * 删除小组成员
     * @return
     */
    @PostMapping("/menuList")
    public JsonResponse<List<MenuDto>> menuList(@RequestBody MenuDto menuDto) {
        return JsonResponse.success(orgService.menuList(menuDto, SecurityUtils.getLoanassistUser()));
    }

    /**
     * 删除小组成员
     * @return
     */
    @PostMapping("/userMenuList")
    public JsonResponse<List<String>> userMenuList(@RequestBody MenuDto menuDto) {
        return JsonResponse.success(orgService.userMenuList(menuDto, SecurityUtils.getLoanassistUser()));
    }

    /**
     * 删除小组成员
     * @return
     */
    @PostMapping("/saveMenu")
    public JsonResponse<MenuDto> saveMenu(@RequestBody MenuDto menuDto) {
        return JsonResponse.success(orgService.saveMenu(menuDto, SecurityUtils.getLoanassistUser()));
    }

}
